Popular Searches
Popular Course Categories
Popular Courses

Opening a URL

WebDriver Fundamentals

Opening a URL in Selenium WebDriver

Opening a URL is one of the most fundamental operations in Selenium WebDriver. After launching a browser, Selenium allows us to navigate to a specific web address and load the requested web page automatically. This operation is commonly used as the first step in Selenium automation because most test scenarios begin by opening an application, website, login page, dashboard, or any other web resource.

In Selenium WebDriver, the get() method is commonly used to navigate the browser to a fully qualified URL. The driver.get(url) command is used to navigate the browser to the specified URL.


1. What Does Opening a URL Mean?

Opening a URL in Selenium means instructing the automated browser to navigate to a particular web address. Instead of manually typing a URL into the browser address bar, Selenium sends a navigation command to the browser through WebDriver.

For example, if we want to open Google, we can use:

driver.get("https://www.google.com");

When Selenium executes this statement, the browser navigates to the specified address.

A URL normally contains a protocol such as https:// followed by the domain name and, optionally, a path, query parameters, or fragments.


2. Why Do We Open URLs in Selenium?

Opening a URL is required before Selenium can interact with most web application elements. A typical automation test begins by launching the browser and navigating to the application under test.

For example, a login test may follow this sequence:

Launch Browser

      ↓

Open Application URL

      ↓

Load Login Page

      ↓

Find Username Field

      ↓

Enter Username

      ↓

Enter Password

      ↓

Click Login

      ↓

Verify Dashboard

Therefore, URL navigation forms an important part of the initial setup of many Selenium test cases.


3. Basic Syntax of Opening a URL

In Selenium Java, the basic syntax is:

driver.get("URL");

Example:

driver.get("https://www.google.com");

Here:

Component Meaning
driver The WebDriver object controlling the browser.
get() The WebDriver method used to navigate to a URL.
URL The web address that should be opened.


4. Prerequisites for Opening a URL

Before opening a URL, a Selenium test generally needs a valid WebDriver session. WebDriver provides the interface used to control browsers, with browser-specific driver implementations handling communication between Selenium and the browser.

The basic requirements are:

  • Java or another supported programming language.
  • Selenium WebDriver library.
  • A supported browser such as Chrome, Firefox, Edge, or Safari.
  • A WebDriver instance.
  • A valid URL.


5. Launching the Browser Before Opening the URL

Normally, we first create a browser driver and then open the required URL.

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class OpenURL {

    public static void main(String[] args) {

 

        WebDriver driver = new ChromeDriver();

 

        driver.get("https://www.google.com");

 

        driver.quit();

    }

}

The statement:

WebDriver driver = new ChromeDriver();

creates a Chrome browser session, while:

driver.get("https://www.google.com");

navigates that browser session to Google.


6. Understanding driver.get()

The get() method is one of the most frequently used WebDriver methods. Selenium's Java API defines get(String url) as loading a new web page in the current browser window. It is also documented as a synonym for the navigation to() method.

Syntax:

driver.get("https://example.com");

Example:

WebDriver driver = new ChromeDriver();

 

driver.get("https://www.selenium.dev");

The browser will navigate to the specified Selenium website.


7. URL Must Normally Be Fully Qualified

The URL supplied to WebDriver should normally include its protocol, such as http:// or https://. The URL supplied to get() should be a complete web address.

Correct:

driver.get("https://www.google.com");

Another correct example:

driver.get("http://example.com");

Avoid using an incomplete address such as:

driver.get("www.google.com");

Always prefer a complete URL:

driver.get("https://www.google.com");


8. Opening a Website

Suppose we want to open the Selenium website.

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class SeleniumWebsite {

    public static void main(String[] args) {

 

        WebDriver driver = new ChromeDriver();

 

        driver.get("https://www.selenium.dev");

 

        driver.quit();

    }

}

The execution flow is:

Start Java Program

       ↓

Create ChromeDriver

       ↓

Start Chrome Browser

       ↓

Execute driver.get()

       ↓

Navigate to Selenium Website

       ↓

Perform Test Actions

       ↓

driver.quit()

       ↓

Close Browser Session


9. Opening a Login Page

In real-world automation, the URL is often a login page.

driver.get("https://example.com/login");

After the page loads, Selenium can locate the login fields and interact with them.

driver.get("https://example.com/login");

 

driver.findElement(By.id("username")).sendKeys("admin");

driver.findElement(By.id("password")).sendKeys("admin123");

driver.findElement(By.id("login")).click();

The URL navigation is therefore the starting point of the login automation flow.


10. Opening a Specific Page

A URL does not have to point only to the home page. Selenium can open a specific application page.

driver.get("https://example.com/products");

Another example:

driver.get("https://example.com/dashboard");

Another example:

driver.get("https://example.com/contact");

This is useful when a test needs to start directly from a particular application module.


11. Opening a URL with Query Parameters

URLs can contain query parameters.

For example:

driver.get("https://example.com/search?q=selenium");

Here, q=selenium is a query parameter.

Another example:

driver.get("https://example.com/products?category=mobile");

Selenium can navigate to such URLs in the same way as other fully qualified URLs.


12. Opening a URL with a Path

A URL can contain a path that identifies a particular resource or page.

driver.get("https://example.com/products/mobile/iphone");

This allows an automation test to directly navigate to the required page without manually navigating through several menus.


13. Opening Multiple URLs

Selenium can navigate to multiple URLs sequentially during the same browser session.

driver.get("https://www.google.com");

 

driver.get("https://www.selenium.dev");

 

driver.get("https://example.com");

The browser will navigate from one URL to the next in the order in which the commands are executed.

The final URL in this example will be:

https://example.com


14. Opening URL and Reading the Page Title

After opening a URL, Selenium can retrieve information about the current page. For example, the page title can be retrieved using getTitle().

WebDriver driver = new ChromeDriver();

 

driver.get("https://www.selenium.dev");

 

String title = driver.getTitle();

 

System.out.println(title);

 

driver.quit();

Selenium automation commonly uses the page title and current URL to verify that the expected page has been opened.


15. Opening URL and Getting Current URL

After navigation, we can retrieve the URL of the current page using getCurrentUrl().

driver.get("https://www.selenium.dev");

 

String currentUrl = driver.getCurrentUrl();

 

System.out.println(currentUrl);

This can be useful for validating whether navigation was successful.


16. URL Validation Example

A simple validation can compare the current URL with the expected URL.

driver.get("https://www.selenium.dev");

 

String actualUrl = driver.getCurrentUrl();

 

String expectedUrl = "https://www.selenium.dev";

 

if (actualUrl.equals(expectedUrl)) {

    System.out.println("URL matched");

} else {

    System.out.println("URL did not match");

}

This type of validation is useful in navigation-related test cases.


17. Using driver.navigate().to()

Selenium also provides a navigation interface through driver.navigate().to().

driver.navigate().to("https://www.google.com");

The navigate() interface provides browser navigation operations, including navigation to a URL, back, forward, and refresh.


18. Difference Between get() and navigate().to()

get() navigate().to()
Used to open a URL. Also used to navigate to a URL.
Simple and commonly used. Part of Selenium's Navigation interface.
Syntax: driver.get(url) Syntax: driver.navigate().to(url)
Very common in basic test scripts. Useful when working with navigation operations such as back and forward.

Example:

driver.get("https://www.google.com");

Equivalent navigation form:

driver.navigate().to("https://www.google.com");


19. Browser Navigation After Opening a URL

Once a URL has been opened, Selenium provides navigation operations such as back, forward, and refresh.

driver.get("https://www.google.com");

 

driver.get("https://www.selenium.dev");

 

driver.navigate().back();

 

driver.navigate().forward();

 

driver.navigate().refresh();

This creates a simple browser navigation flow:

Google

  ↓

Selenium

  ↓

Back

  ↓

Google

  ↓

Forward

  ↓

Selenium

  ↓

Refresh


20. Opening URL in Chrome

Chrome is one of the commonly used browsers for Selenium automation.

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class ChromeURL {

    public static void main(String[] args) {

 

        WebDriver driver = new ChromeDriver();

 

        driver.get("https://www.google.com");

 

        driver.quit();

    }

}


21. Opening URL in Firefox

The same concept can be used with Firefox.

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

 

public class FirefoxURL {

    public static void main(String[] args) {

 

        WebDriver driver = new FirefoxDriver();

 

        driver.get("https://www.google.com");

 

        driver.quit();

    }

}


22. Opening URL in Microsoft Edge

Microsoft Edge can also be controlled using Selenium.

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.edge.EdgeDriver;

 

public class EdgeURL {

    public static void main(String[] args) {

 

        WebDriver driver = new EdgeDriver();

 

        driver.get("https://www.google.com");

 

        driver.quit();

    }

}


23. Opening URL Using Selenium WebDriver

The basic architecture can be represented as:

Java Test Code

      ↓

WebDriver API

      ↓

Browser Driver

      ↓

Browser

      ↓

Requested URL

      ↓

Web Page

Selenium WebDriver provides a language-neutral interface for controlling browsers, while browser-specific drivers communicate with the corresponding browser.


24. Complete Basic Example

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class OpenWebsite {

 

    public static void main(String[] args) {

 

        WebDriver driver = new ChromeDriver();

 

        driver.get("https://www.google.com");

 

        System.out.println("Page Title: " + driver.getTitle());

        System.out.println("Current URL: " + driver.getCurrentUrl());

 

        driver.quit();

    }

}

This example performs the following operations:

  1. Creates a Chrome browser session.
  2. Opens Google.
  3. Gets the page title.
  4. Gets the current URL.
  5. Closes the complete browser session.


25. Opening URL with a Variable

Instead of hardcoding a URL directly inside get(), we can store it in a variable.

String url = "https://www.google.com";

 

driver.get(url);

This approach becomes useful when URLs are read from configuration files, environment variables, test data, or other external sources.


26. Opening URL from Configuration

In larger automation frameworks, URLs are often maintained outside the test code.

For example, a configuration file may contain:

baseUrl=https://example.com

The test framework can read this value and pass it to WebDriver.

String baseUrl = "https://example.com";

 

driver.get(baseUrl);

This makes it easier to change environments such as development, QA, staging, and production.


27. Opening Different Environment URLs

Real-world applications may have different URLs for different environments.

Environment Example URL
Development https://dev.example.com
QA https://qa.example.com
Staging https://staging.example.com
Production https://www.example.com

The same Selenium test can potentially be executed against different environments by changing the base URL configuration.


28. Opening URL Before Finding Elements

A common beginner mistake is trying to locate elements before navigating to the required page.

Correct sequence:

driver.get("https://example.com/login");

 

driver.findElement(By.id("username"));

Instead of attempting to find login elements before opening the login page.

The general sequence is:

Launch Browser

      ↓

Open URL

      ↓

Wait for Page State

      ↓

Locate Element

      ↓

Perform Action

      ↓

Validate Result


29. Opening URL and Performing a Search

Example:

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class SearchExample {

 

    public static void main(String[] args) {

 

        WebDriver driver = new ChromeDriver();

 

        driver.get("https://www.google.com");

 

        driver.findElement(By.name("q"))

              .sendKeys("Selenium WebDriver");

 

        driver.findElement(By.name("q"))

              .submit();

 

        driver.quit();

    }

}

This demonstrates how URL navigation becomes the first step before interacting with page elements.


30. Opening URL and Performing Login

A typical login automation flow may look like:

driver.get("https://example.com/login");

 

driver.findElement(By.id("username"))

      .sendKeys("testuser");

 

driver.findElement(By.id("password"))

      .sendKeys("password123");

 

driver.findElement(By.id("loginButton"))

      .click();

The URL navigation is performed first, followed by element interactions.


31. Opening URL and Verifying Title

driver.get("https://www.selenium.dev");

 

String title = driver.getTitle();

 

System.out.println("Title: " + title);

In an actual test framework, the title can be compared with an expected value using an assertion.

String expectedTitle = "Selenium";

String actualTitle = driver.getTitle();

 

if (actualTitle.contains(expectedTitle)) {

    System.out.println("Title verification passed");

} else {

    System.out.println("Title verification failed");

}


32. Opening URL and Verifying Current URL

driver.get("https://www.selenium.dev");

 

String expectedUrl = "https://www.selenium.dev/";

String actualUrl = driver.getCurrentUrl();

 

System.out.println("Expected URL: " + expectedUrl);

System.out.println("Actual URL: " + actualUrl);

Remember that a website can redirect from one URL to another, so the final current URL may not always be textually identical to the initially requested URL.


33. URL Redirection

Web applications can redirect users from one URL to another. For example:

driver.get("https://example.com");

The application may redirect the browser to:

https://www.example.com/

Therefore, when validating navigation, it can be useful to check the final current URL using:

driver.getCurrentUrl();


34. Opening URL and Waiting for Page Load

The get() method navigates the browser to the requested page according to the configured WebDriver page-load strategy.

Basic example:

driver.get("https://example.com");

After navigation, Selenium can continue with further commands according to the state of the page and the synchronization strategy used by the test.


35. Opening URL in a Headless Browser

In headless execution, the browser runs without displaying a normal graphical browser window. This is frequently useful in automated environments and CI/CD systems.

Example using ChromeOptions:

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.chrome.ChromeOptions;

 

public class HeadlessURL {

 

    public static void main(String[] args) {

 

        ChromeOptions options = new ChromeOptions();

        options.addArguments("--headless=new");

 

        WebDriver driver = new ChromeDriver(options);

 

        driver.get("https://www.google.com");

 

        System.out.println(driver.getTitle());

 

        driver.quit();

    }

}


36. Opening URL in a Maximized Browser

After opening the browser, the window can be maximized.

driver.manage().window().maximize();

 

driver.get("https://www.google.com");

Another common sequence is:

WebDriver driver = new ChromeDriver();

 

driver.manage().window().maximize();

 

driver.get("https://www.google.com");


37. Opening URL and Taking a Screenshot

After navigating to a URL, Selenium can be used together with the screenshot API to capture the current browser state.

driver.get("https://www.google.com");

 

File screenshot = ((TakesScreenshot) driver)

        .getScreenshotAs(OutputType.FILE);

This is useful for debugging failed tests and documenting test execution.


38. Opening URL in a TestNG Test

URL navigation is frequently performed inside a TestNG test or setup method.

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

 

public class URLTest {

 

    WebDriver driver;

 

    @BeforeMethod

    public void setUp() {

        driver = new ChromeDriver();

    }

 

    @Test

    public void openURL() {

        driver.get("https://www.google.com");

 

        System.out.println(driver.getTitle());

    }

 

    @AfterMethod

    public void tearDown() {

        driver.quit();

    }

}


39. Opening URL Using Page Object Model

In a Page Object Model framework, the navigation URL is often handled through a page object or base test configuration.

public class LoginPage {

 

    WebDriver driver;

 

    public LoginPage(WebDriver driver) {

        this.driver = driver;

    }

 

    public void openLoginPage() {

        driver.get("https://example.com/login");

    }

}

The test can then call:

LoginPage loginPage = new LoginPage(driver);

 

loginPage.openLoginPage();


40. Opening URL in a Browser Factory

A browser factory can centralize browser creation.

public class BrowserFactory {

 

    public static WebDriver createDriver() {

 

        return new ChromeDriver();

    }

}

The test can then use:

WebDriver driver = BrowserFactory.createDriver();

 

driver.get("https://example.com");

This design becomes useful when a framework supports multiple browsers.


41. Opening URL in Cross-Browser Testing

The same URL can be opened in different browsers.

WebDriver driver;

 

driver = new ChromeDriver();

driver.get("https://example.com");

driver.quit();

 

driver = new FirefoxDriver();

driver.get("https://example.com");

driver.quit();

 

driver = new EdgeDriver();

driver.get("https://example.com");

driver.quit();

Selenium supports automation across major browsers through WebDriver implementations.


42. Common Errors While Opening a URL

Error 1: Invalid URL

driver.get("www.google.com");

Use a complete URL:

driver.get("https://www.google.com");

Error 2: Driver Not Created

Calling:

driver.get("https://example.com");

before creating the WebDriver instance will not work.

Correct:

WebDriver driver = new ChromeDriver();

 

driver.get("https://example.com");

Error 3: Browser Driver Problem

If the browser session cannot be created because of an environment or driver configuration problem, URL navigation cannot begin.

Error 4: Network Problem

If the machine cannot access the requested website, the navigation may fail or the page may not load as expected.


43. Common Beginner Mistakes

  • Forgetting to create the WebDriver object.
  • Using an incomplete URL.
  • Trying to find elements before opening the page.
  • Not closing the browser after the test.
  • Hardcoding environment-specific URLs unnecessarily.
  • Not validating the final URL after a redirect.
  • Ignoring synchronization problems after navigation.
  • Using incorrect browser configuration.
  • Assuming the requested URL and final URL will always be identical.


44. Best Practices for Opening URLs

  • Use fully qualified URLs containing the appropriate protocol.
  • Store environment-specific URLs in configuration when appropriate.
  • Keep browser initialization separate from test logic in larger frameworks.
  • Validate navigation when URL correctness is important to the test.
  • Use getCurrentUrl() when the final destination needs to be verified.
  • Use getTitle() when title verification is relevant.
  • Always close the WebDriver session using quit() after execution.
  • Use a consistent browser-management strategy across the automation framework.


45. Real-World URL Navigation Flow

A real-world Selenium automation framework may follow this architecture:

Test Case

   ↓

Test Configuration

   ↓

Browser Factory

   ↓

Create WebDriver

   ↓

Open Base URL

   ↓

Page Object

   ↓

Find Elements

   ↓

Perform Actions

   ↓

Assertions

   ↓

Test Report

   ↓

Quit Browser


46. Complete Practical Example

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class CompleteURLExample {

 

    public static void main(String[] args) {

 

        WebDriver driver = new ChromeDriver();

 

        try {

 

            driver.manage().window().maximize();

 

            driver.get("https://www.google.com");

 

            System.out.println("Title: " + driver.getTitle());

            System.out.println("Current URL: " + driver.getCurrentUrl());

 

            driver.findElement(By.name("q"))

                  .sendKeys("Selenium WebDriver");

 

            driver.findElement(By.name("q"))

                  .submit();

 

            System.out.println("Search completed");

 

        } finally {

 

            driver.quit();

        }

    }

}

This example demonstrates a practical flow of launching the browser, opening a URL, retrieving browser information, interacting with a web element, and finally terminating the browser session.


47. Practical Project: Open and Validate Website

Project Objective: Create a Selenium program that opens a website and verifies its title and current URL.

Step 1: Launch Browser

WebDriver driver = new ChromeDriver();

Step 2: Open Website

driver.get("https://www.selenium.dev");

Step 3: Get Title

String title = driver.getTitle();

Step 4: Get Current URL

String url = driver.getCurrentUrl();

Step 5: Print Results

System.out.println("Title: " + title);

System.out.println("URL: " + url);

Step 6: Close Browser

driver.quit();


48. Complete Project Code

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class WebsiteValidation {

 

    public static void main(String[] args) {

 

        WebDriver driver = new ChromeDriver();

 

        try {

 

            driver.manage().window().maximize();

 

            driver.get("https://www.selenium.dev");

 

            String title = driver.getTitle();

            String currentUrl = driver.getCurrentUrl();

 

            System.out.println("Page Title: " + title);

            System.out.println("Current URL: " + currentUrl);

 

            if (currentUrl.contains("selenium.dev")) {

                System.out.println("URL validation passed");

            } else {

                System.out.println("URL validation failed");

            }

 

        } finally {

 

            driver.quit();

        }

    }

}


49. Opening URL in Selenium Automation Framework

In a professional Selenium framework, URL navigation is generally part of the test setup or page navigation layer rather than being repeated unnecessarily throughout every test.

For example:

public class BaseTest {

 

    protected WebDriver driver;

 

    public void setUp() {

        driver = new ChromeDriver();

        driver.get("https://example.com");

    }

 

    public void tearDown() {

        driver.quit();

    }

}

Individual tests can then begin from a known application state.


50. URL Navigation and Page Objects

Page Object Model can encapsulate page navigation.

public class HomePage {

 

    private WebDriver driver;

 

    public HomePage(WebDriver driver) {

        this.driver = driver;

    }

 

    public void open() {

        driver.get("https://example.com");

    }

 

    public String getPageTitle() {

        return driver.getTitle();

    }

}

This approach keeps navigation-related code organized and reusable.


51. URL Navigation and Assertions

Opening a URL and validating the result are two separate activities.

driver.get("https://example.com");

 

String actualUrl = driver.getCurrentUrl();

 

Assert.assertTrue(actualUrl.contains("example.com"));

The first statement performs navigation, while the second validates the resulting browser state.


52. Opening URL vs Clicking a Link

Opening URL Clicking Link
Uses driver.get() or navigation methods. Uses WebElement.click().
Directly navigates to a specified address. Simulates a user clicking a link.
Useful for direct navigation. Useful for testing actual UI navigation.

Example of direct URL navigation:

driver.get("https://example.com/products");

Example of link navigation:

driver.findElement(By.linkText("Products")).click();


53. URL Navigation in Selenium Architecture

Application Test

      ↓

Selenium WebDriver API

      ↓

Navigation Command

      ↓

Browser Driver

      ↓

Browser

      ↓

HTTP/HTTPS Request

      ↓

Web Server

      ↓

Web Page Response

      ↓

Browser Renders Page

The Selenium WebDriver API provides the commands used by the automation code, while the browser and its driver handle the actual browser-level communication.


54. Selenium Manager and Browser Setup

Modern Selenium releases include Selenium Manager, which can assist with browser-driver management. Selenium Manager can automatically handle browser driver installation in supported Selenium workflows.

For example, modern Selenium Java code can commonly start a Chrome session using:

WebDriver driver = new ChromeDriver();

 

driver.get("https://example.com");

The exact environment requirements can still depend on the installed browser, Selenium version, operating system, and project configuration.


55. Interview Question: How Do You Open a URL in Selenium?

Answer: We can use the get() method of WebDriver.

driver.get("https://www.google.com");

The method navigates the current browser window to the specified URL.


56. Interview Question: What Is driver.get()?

Answer: driver.get() is a WebDriver method used to navigate the browser to a specified URL.

driver.get("https://example.com");

The method loads a new web page in the current browser window.


57. Interview Question: What Is the Difference Between get() and navigate().to()?

Answer: Both can be used to navigate to a URL. The get() method provides a simple direct API, while navigate() provides the browser navigation interface, including operations such as back, forward, refresh, and navigation to a URL.


58. Interview Question: Can Selenium Open Any URL?

Answer: Selenium can navigate to web URLs that the browser and test environment can access, provided the URL is valid and appropriately formatted. The URL should normally include its protocol such as https:// or http://.


59. Interview Question: How Can You Get the Current URL?

Answer: Use getCurrentUrl().

String currentUrl = driver.getCurrentUrl();

 

System.out.println(currentUrl);

This method retrieves the URL of the current page.


60. Quick Revision

Concept Syntax
Create Chrome browser WebDriver driver = new ChromeDriver();
Open URL driver.get("https://example.com");
Navigate to URL driver.navigate().to("https://example.com");
Get page title driver.getTitle();
Get current URL driver.getCurrentUrl();
Go back driver.navigate().back();
Go forward driver.navigate().forward();
Refresh page driver.navigate().refresh();
Close browser session driver.quit();


61. Complete URL Opening Flow

Start Test

    ↓

Create WebDriver

    ↓

Launch Browser

    ↓

Prepare Fully Qualified URL

    ↓

driver.get(URL)

    ↓

Browser Navigates

    ↓

Page Loads

    ↓

Get Title / Current URL

    ↓

Find Elements

    ↓

Perform Actions

    ↓

Validate Result

    ↓

driver.quit()

    ↓

End Test


62. Learning Outcomes

After completing this topic, you should be able to:

  • Understand what URL navigation means in Selenium.
  • Use driver.get() to open a web page.
  • Use driver.navigate().to() for URL navigation.
  • Understand the difference between direct URL navigation and clicking a link.
  • Use fully qualified URLs in Selenium.
  • Open specific pages and application routes.
  • Retrieve the current URL using getCurrentUrl().
  • Retrieve the page title using getTitle().
  • Navigate backward, forward, and refresh the browser.
  • Build practical URL-navigation test cases.
  • Use URL navigation in TestNG and Page Object Model frameworks.
  • Understand the role of WebDriver in browser navigation.


63. Recommended Selenium Training Resource

For structured Selenium Automation Testing training, you can explore the JustAcademy Selenium training course:

JustAcademy Selenium Automation Testing Course

You can also register for a course demo using the following link:

Register for Selenium Course Demo


64. Final Summary

Opening a URL is one of the first and most important operations performed in Selenium WebDriver automation. After creating a WebDriver session, the test can use driver.get() to navigate the browser to a fully qualified URL. Selenium also provides the navigation interface through driver.navigate().to(), along with browser-history operations such as back, forward, and refresh.

A typical Selenium workflow is:

WebDriver driver = new ChromeDriver();

 

driver.get("https://example.com");

 

System.out.println(driver.getTitle());

System.out.println(driver.getCurrentUrl());

 

driver.quit();

Understanding URL navigation provides the foundation for more advanced Selenium operations such as locating elements, performing clicks, entering data, handling forms, validating pages, implementing Page Object Model frameworks, performing cross-browser testing, and building complete end-to-end automation frameworks.

whatsapp